package com.qf.controller;

import com.qf.entity.Orders;
import com.qf.entity.WebOrder;
import com.qf.exception.BizException;
import com.qf.exception.ControllerException;
import com.qf.service.IOrdersService;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/orders")
public class OrdersController {

    private IOrdersService iOrdersService;

   public OrdersController(IOrdersService iOrdersService){
       this.iOrdersService=iOrdersService;
   }

    //getById/1/28
    @GetMapping("/getById/{oStatus}/{oUserId}")
   public Object queryById(@PathVariable("oStatus") int oStatus,@PathVariable("oUserId") int oUserId ){
       List<Orders> list = null;
       Orders orders = null;

       try {
           list = iOrdersService.queryById( oStatus , oUserId);
           System.out.println(list);
       }catch (BizException e){
           throw e;
       }catch (Exception ex){
           throw new ControllerException("控制层异常:" + ex.getMessage());
       }

       return list;
   }

   @RequestMapping("/selectNoPay/{status}/{userId}")
    public List<Orders> selectNoPay(@PathVariable("status") int status,@PathVariable("userId") int userId){


       List<Orders> orders = null;
               try {
                   orders   = iOrdersService.selectNoPay(status, userId);
               }catch (BizException e){
                   throw  e;
               }catch (Exception ex){
                   throw new ControllerException("控制层异常:" + ex.getMessage());
               }
       return orders;
   }

   @RequestMapping("/queryAll/{userId}")
    public List<Orders> queryAll(@PathVariable("userId")int userId){
       Orders orders=new Orders();
       orders.setoUserId(userId);
       List<Orders> ordersList = iOrdersService.queryAll(orders);
       return ordersList;
   }

   @RequestMapping("/getOrdersByStatus/{status}/{userId}")
   public List<WebOrder> getOrdersByStatus(@PathVariable("status") int status,@PathVariable("userId") int userId){

       List<WebOrder> ordersByStatus = iOrdersService.getOrdersByStatus( status,userId);
       return ordersByStatus;

   }

   @RequestMapping("/deleteById/{oNo}")
   public int deleteById(@PathVariable("oNo") String oNo){

         return iOrdersService.deleteById(oNo);

   }
}
